package com.lujieni.sentinel.service;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class HelloService {

    @SentinelResource(value = "degrade520", fallback = "degradeHandler")
    public Integer degrade(Integer num){
        System.out.println("degrade method run");
        if(Objects.equals(-1, num)){
            throw new RuntimeException("error");
        }
        return num;
    }

    // 必须为public类型 参数类型必须和原方法相匹配且最后一个参数为 Throwable
    // fallback即能够处理限流后的异常返回也能处理降级后的异常返回
    public Integer degradeHandler(Integer num, Throwable e){
        return -100;
    }

}
